<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import Timer from './Timer/index.vue'

const route = ref('')
const enterAction = ref({})

onMounted(() => {
  // 检查是否在 uTools 环境中运行
  if (typeof window.utools !== 'undefined' && window.utools) {
    window.utools.onPluginEnter((action) => {
      route.value = action.code
      enterAction.value = action
    })
    window.utools.onPluginOut((isKill) => {
      route.value = ''
    })
  } else {
    // 开发环境默认显示计时器
    route.value = 'timer'
  }
})
</script>

<template>
  <template v-if="route === 'timer'">
    <Timer :enterAction="enterAction"></Timer>
  </template>
  <template v-if="route === 'hello'">
    <Hello :enterAction="enterAction"></Hello>
  </template>
  <template v-if="route === 'read'">
    <Read :enterAction="enterAction"></Read>
  </template>
  <template v-if="route === 'write'">
    <Write :enterAction="enterAction"></Write>
  </template>
</template>
